﻿/******************************************************************************
* File description: BoxExpRescue.qml
* Function: 实验恢复弹窗
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.12
import QtQuick.Controls 2.12
import "../components"

CustomPopupBox {

    id: root

    title: "实验恢复"

    height: 480*dp; width: 560*dp

    property int    module1: 1
    property int    module2: 1
    property int    step1: 10
    property int    step2: 11
    property string stepInfo1: "打开阀门1,2,3"
    property string stepInfo2: "推注射器6"


    property int selectedIdx: -1


    contentItem: Item{

        Column{
            x: 20*dp
            width: parent.width - 2*x
            spacing: 10*dp
            Text {
                text: qsTr("检测到设备有未完成的实验，是否继续？")
                font.pixelSize: config.fontsize
                height: 40*dp
                width: parent.width
                verticalAlignment: Text.AlignVCenter

            }
            BoxExpRescueItem{
                icon: "qrc:/picture/controlPannelButton/stop.png"
                content: "停止当前实验"
                isSelected: selectedIdx === 0
                onClicked: {
                    selectedIdx = 0
                }
            }
            BoxExpRescueItem{
                icon: "qrc:/picture/controlPannelButton/run.png"
                content: "重新执行当前步骤 【" + gModuleName[module1] + "】 步骤" + step1 + " - " + stepInfo1
                isSelected: selectedIdx === 1
                onClicked: {
                    selectedIdx = 1
                }
            }
            BoxExpRescueItem{
                enabled: step2 > 0
                icon: step2 > 0 ? "qrc:/picture/controlPannelButton/continuenue.png" : "qrc:/picture/controlPannelButton/continue_d.png"
                content: {
                    if(step2 > 0)  return "执行下一步骤 【" + gModuleName[module2] + "】 步骤" + step2 + " - " + stepInfo2
                    else           return "执行下一步骤 【当前步骤已经是最后一步了】"

                }
                isSelected: selectedIdx === 2
                onClicked: {
                    selectedIdx = 2
                }
            }
            CustomCheckBox{
                id: checked_union
                height: 30*dp
                title: "继续并发步骤"
                editable: selectedIdx !== 0
                checked: false
                autoChecked: true
            }
            Row{
                anchors.horizontalCenter: parent.horizontalCenter
                spacing: 15*dp
//                CustomButton{
//                    title: "取消"
//                    defaultMode2: true
//                    onClicked: {
//                        root.close()
//                    }
//                }
                CustomButton{
                    title: "确定"
                    defaultMode1: true
                    onClicked: {
                        if(selectedIdx < 0){
                            toast.show("请选择后再点击确定！", 1)
                        }else{
                            root.close()
                            // 不执行
                            if(selectedIdx === 0){
                                CommunicationMethod.continueExperiment(-1, checked_union?1:0)       // 不继续 ([checked_union]是否继续并发0不继续 1继续）
                                root.close()
                                return
                            }
                            // 重新执行当前步骤
                            else if(selectedIdx === 1){
                                gStateExp.syncStateFromDB()
                                gPageIdx = module1
                                CommunicationMethod.continueExperiment(0, checked_union?1:0)       // 0重新执行当前步骤
                                CAnimationRescue.parseDBInstruct(step1)
                            }
                            // 执行下一步骤
                            else if(selectedIdx === 2){
                                gStateExp.syncStateFromDB()
                                gPageIdx = module2
                                CommunicationMethod.continueExperiment(1, checked_union?1:0)       // 1重新执行当前步骤
                                CAnimationRescue.parseDBInstruct(step2)
                            }
                        }
                    }
                }
            }

        }

    }


}
